package com.gpframework.module.controller.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.gpframework.common.enums.PhoneMsgTypeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.sys.domain.SmsStock;
import com.gpframework.module.sys.domain.vo.SmsStockVo;
import com.gpframework.module.sys.domain.req.SmsStockReq;
import com.gpframework.module.sys.domain.req.SmsStockAdd;
import com.gpframework.module.sys.domain.req.SmsStockUpdate;
import com.gpframework.module.sys.service.ISmsStockService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName SmsStockController
 * @Author gpframework
 * @Date 2022-06-16
 * @Version 1.0.0
 * @Description 运营中心短信库存Controller
 */
@Validated
@Api(tags = "运营中心短信库存")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/sys/smsStock" )
public class SmsStockController extends BaseController {

    private final ISmsStockService iSmsStockService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2022-06-16
  * @Param smsStock
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('sys:smsStock:list')")
    @GetMapping("/list")
    public TableDataInfo<SmsStockVo> list(SmsStockReq smsStockReq)
    {
        startPage();
        QueryWrapper<SmsStock> lqw = new QueryWrapper<SmsStock>();
        smsStockReq.generatorQuery(lqw,true);
        List<SmsStockVo> list = iSmsStockService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2022-06-16
     * @Param smsStock
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('sys:smsStock:add')" )
    @Log(title = "添加运营中心短信库存" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody SmsStockAdd smsStockAdd) {
        SmsStock smsStock = Convert.convert(new TypeReference<SmsStock>() {}, smsStockAdd);
        return toAjax(iSmsStockService.save(smsStock) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2022-06-16
     * @Param smsStock
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('sys:smsStock:edit')" )
    @Log(title = "修改运营中心短信库存" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody SmsStockUpdate smsStockUpdate) {
        SmsStock smsStock = Convert.convert(new TypeReference<SmsStock>() {}, smsStockUpdate);
        return toAjax(iSmsStockService.updateById(smsStock) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2022-06-16
     * @Param smsStock
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('sys:smsStock:export')" )
    @Log(title = "导出运营中心短信库存" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(SmsStockReq smsStockReq) {
        QueryWrapper<SmsStock> lqw = new QueryWrapper<SmsStock>();
        smsStockReq.generatorQuery(lqw,true);
        List<SmsStockVo> list = iSmsStockService.listVo(lqw);
        ExcelUtil<SmsStockVo> util = new ExcelUtil<SmsStockVo>(SmsStockVo. class);
        return util.exportExcel(list, "smsStock" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2022-06-16
     * @Param smsStock
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('sys:smsStock:query')" )
    @GetMapping(value = "/{smsStockId}" )
    public AjaxResult<SmsStockVo> getInfo(@PathVariable("smsStockId" ) Long smsStockId) {
        return AjaxResult.success(iSmsStockService.getVoById(smsStockId));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2022-06-16
     * @Param smsStock
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('sys:smsStock:remove')" )
    @Log(title = "删除运营中心短信库存" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{smsStockIds}" )
    public AjaxResult remove(@PathVariable Long[] smsStockIds) {
        return toAjax(iSmsStockService.removeByIds(Arrays.asList(smsStockIds)) ? 1 : 0);
    }


}
